﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
   public class Ctbl_Support:IData<tbl_Support>
    {
       public Ctbl_Support(String myconnecString) : base(myconnecString) { }


       protected override int InsertOnSubmit(tbl_Support item, int t)
       {
           return connec.ExecuteNonQuery("ProSupport", CommandType.StoredProcedure, new SqlParameter("@flag", t),
               new SqlParameter("@"+tbl_Support.c_addedDate,item.AddedDate),new SqlParameter("@"+tbl_Support.c_bodyQuestion,item.BodyQuestion),
               new SqlParameter("@"+tbl_Support.c_bodyReply,item.BodyReply),new SqlParameter("@"+tbl_Support.c_congty,item.Congty),
               new SqlParameter("@"+tbl_Support.c_diachi,item.Diachi),new SqlParameter("@"+tbl_Support.c_email,item.Email),
               new SqlParameter("@"+tbl_Support.c_hoten,item.Hoten),new SqlParameter("@"+tbl_Support.c_idMember,item.IdMember),
               new SqlParameter("@"+tbl_Support.c_idSupport,item.IdSupport),new SqlParameter("@"+tbl_Support.c_isActive,item.IsActive),
               new SqlParameter("@"+tbl_Support.c_isTraloi,item.IsTraloi),new SqlParameter("@"+tbl_Support.c_masothue,item.Masothue));

       }

       public override List<tbl_Support> GetAll(tbl_Support item)
       {
           throw new NotImplementedException();
       }

       public override tbl_Support GetItemById(object id)
       {
           return GetAll().SingleOrDefault(p => p.IdSupport == Convert.ToInt32(id));
       }

       public override tbl_Support GetItem(IDataReader dr)
       {
           tbl_Support obj = new tbl_Support();
           obj.AddedDate = dr[tbl_Support.c_addedDate] != null ? Convert.ToDateTime(dr[tbl_Support.c_addedDate]) : DateTime.Now;
           obj.BodyQuestion = dr[tbl_Support.c_bodyQuestion].ToString();
           obj.BodyReply = dr[tbl_Support.c_bodyReply].ToString();
           obj.Congty = dr[tbl_Support.c_congty].ToString();
           obj.Diachi = dr[tbl_Support.c_diachi].ToString();
           obj.Email = dr[tbl_Support.c_email].ToString();
           obj.Hoten = dr[tbl_Support.c_hoten].ToString();
           obj.IdMember =Convert.ToInt32(dr[tbl_Support.c_idMember]);
           obj.IdSupport = Convert.ToInt32(dr[tbl_Support.c_idSupport]);
           obj.IsActive = Convert.ToInt32(dr[tbl_Support.c_isActive]);
           obj.IsTraloi = Convert.ToBoolean(dr[tbl_Support.c_isTraloi]);
           obj.Masothue = dr[tbl_Support.c_masothue].ToString();
           return obj;
       }

       public override List<tbl_Support> GetAll()
       {
           return GetAll("select * from "+tbl_Support.b_tbl_Support,CommandType.Text);
       }

    }
}
